package numberone;

import java.security.Key;
import java.util.Arrays;
import java.util.Scanner;

/**
 * 二分查找
 * @author ray
 * @data  2020/2/10
 */
public class BinarySearch {
    public static int rank(int key , int [] a) {
        int lo = 0;
        int hi = a.length - 1;
        while (lo <= hi) {
            int mid = lo + (hi - lo) / 2;
            if (key < a[mid]) hi = mid - 1;
            else if (key > a[mid]) lo = mid + 1;
            else return mid;
        }
        return -1;
    }
    public static void main(String[] args) {
        int [] arr ={12,123,123,15,3032,23,55};
        Arrays.sort(arr);

        int rank = rank(123, arr);
        System.out.println("rank = " + rank);
    }
}
